<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>采购订单管理</title>
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/logic/purchase";
		var basic_WUrl="logic/purchase";
		var basic_Title="添加";
		var show_Width=880;
		var show_Hight=500;
		var grid;
		function createSearch(){
			init(1,8,'100,100,100,100,100,100,100,100','10%');
			//第一行的数据
			addCommon(0,0,"lable","采购编号：");
			addCommon(0,1,"txtlike","zd020Code");
			addCommon(0,2,"lable","单据状态：");
			addCommon(0,3,"selectEnum","zd011Status","<option></option><option value='PHS_SAVE'>草稿</option>"+
					"<option value='PHS_SUBMIT'>已提交</option><option value='PHS_APPROVE'>审核完成</option><option value='PHS_BACK'>已退回</option>");
			addCommon(0,4,"lable","PI编号：");
			addCommon(0,5,"txtlike","zd012PiCode");
		}
		
		function searchAP(){
			multipleSearch("#table1",true,"",basic_Url+"/list.do");
		}
		document.onkeydown=keyListener;   
		function keyListener(e){   
		    e = e ? e : event;  
		    if(e.keyCode == 13){   
		    	searchAP();
		    }   
		}  
		$(function() {
			grid = $("#table1").ligerGrid({
		        columns: [
							  { display: 'id', name: 'id',hide:1,width:1},
			                  { display: '采购编号', name: 'zd020Code', width: 200 },
			                  { display: 'PI编号', name: 'zd012PiCode', width: 200 },
			                  { display: '单据状态', name: 'zd011Status', width: 200, render : function(item){
			                	  if(item.zd011Status=='PHS_SAVE'){
			                		  return '草稿';
			                	  }else if(item.zd011Status=='PHS_SUBMIT'){
			                		  return '已提交';
			                	  }else if(item.zd011Status=='PHS_AUDIT'){
			                		  return '二级审核';
			                	  }else if(item.zd011Status=='PHS_APPROVE'){
			                		  return '审核完成';
			                	  }else if(item.zd011Status=='PHS_BACK'){
			                		  return '已退回';
			                	  }else{
			                		  return '已完结';
			                	  }
			                  }},
			                  { display: '库存状态', name: 'zd011WhStatus', width: 200, render : function(item){
			                	  if(item.zd011WhStatus=='PCSWH_NO'){
			                		  return '未入库';
			                	  }
			                	  if(item.zd011WhStatus=='PCSWH_ST'){
			                		  return '部分入库';
			                	  }
			                	  if(item.zd011WhStatus=='PCSWH_CP'){
			                		  return '完全入库';
			                	  }
			                  }},
			                  { display: '创建人', name: 'bizCreatorName', width: 150},
			                  { display: '创建日期', name: 'bizCreatorDate', width: 150,
			                	  render: function (item){
			                		  var cdate=new Date(item.bizCreatorDate);
			                		  return formatDate(cdate,"yyyy-MM-dd");
			                	  }},
			                  { display: '备注', name: 'zd017Remark', width: 150 }
	                      ],  usePager: true,pageSize:15,pageSizeOptions :[15,30,45,60],enabledSort:false,
	                      url : basic_Url+"/list.do",
	                      width: "100%", height:"98%", checkbox: true,rownumbers:true,      
	                      onDblClickRow : function (data, rowindex, rowobj){
	                    	  edit(data);
	                       }
	                  });
			$("#pageloading").hide();
		});
		function editdg() {
				var manager = $("#table1").ligerGetGridManager(); 
				var data = manager.getSelectedRow(); 
				if(data==null){
					$.dialog.alert("请选择一行数据");
					return false;
				}
	    	   $.dialog({id:"operate", title:"修改抵港时间", content:"url:${ctx}/yd/logic/po/operatetime/edit/"+data.id+".do", width:500, height:300,max:false,lock:true});
	    }
		
		function checkdel(){
			var manager = $("#table1").ligerGetGridManager(); 
			var rows = manager.getSelectedRows();
			var bol = false;
			if (rows==null||rows.length==0){
				$.dialog.alert('请选择需要操作删除的行！');
				return;
			}else{
				
				for(var i=0;i<rows.length;i++){
				 	if (rows[i].bizCreatorName !='${user.name}'){
				 		bol = true;
					}
				}
				if(bol){
					$.dialog.alert('只能对本人建的单据进行删除操作!');
					return;
				}else{
					bol = false;
					for(var i=0;i<rows.length;i++){
					 	if (rows[i].zd011Status == 'PHS_SAVE' || rows[i].zd011Status =='PHS_BACK'){
					 		bol = true;
						}
					}
					if(bol){
						del();
						bol = false;
					}else{
						$.dialog.alert('草稿或已退回状态的单据才能进行删除!');
						return;
					}
				}
			}
		}
	</script>
	
  </head>
 <body style="padding:10px" onLoad="createSearch()">  
       <div id="layout1">
          <div class="panelBar">
	            <ul class="toolBar">
		           <li><a class="add" onclick="add()"><span>新增</span></a></li>
		            <webres:displaycontroller elementId="PO_DELETE" description="采购订单删除">
		       			<li><a class="delete" onclick="checkdel()"><span>删除</span></a></li>
		      		</webres:displaycontroller>
               </ul>
          </div>
          <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
      </div>
      <div position="center" id="table1">
      </div>
      <div class="clear"></div>
   </div>
    </body>
</html>